package com.foxzzz.two.pointers;

import java.util.Arrays;

public class Solution88 {
    public void merge1(int[] nums1, int m, int[] nums2, int n) {
        System.arraycopy(nums2, 0, nums1, m, n);
        Arrays.sort(nums1);
    }

    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int start = m - 1;
        int end = m + n - 1;
        for (int i = n - 1; i >= 0; ) {
            if (start < 0 || nums2[i] > nums1[start]) {
                nums1[end] = nums2[i];
                i--;
            } else {
                nums1[end] = nums1[start];
                start--;
            }
            end--;
        }
        return;
    }

    public static void main(String[] args) {
        new Solution88().merge(new int[]{0}, 0, new int[]{1}, 1);
        new Solution88().merge(new int[]{1, 2, 3, 0, 0, 0}, 3, new int[]{2, 5, 6}, 3);


    }
}
